#include"appconfig.h"
#include<mutex>
#include<QDebug>

std::unique_ptr<AppConfig> AppConfig::instance_ = nullptr;
#define VIDEO_PATH ""
AppConfig::~AppConfig()
{

}

AppConfig *AppConfig::instance()
{
    static std::once_flag flag;
    std::call_once(flag,[&](){
        instance_.reset(new AppConfig());
    });
    return instance_.get();
}

QVector<QVariantMap> AppConfig::getVideoFiles() const
{
    QVector<QVariantMap> resultList;
    if(!videoDir.exists())
    {
        return  resultList;
    }
    QStringList nameFilters;
    nameFilters<<"*.m3u8"<<"*.ts"<<"*.mp4"<<"*.flv"<<"*.mkv";
    QFileInfoList fileInfoList = videoDir.entryInfoList(
                nameFilters,QDir::Files | QDir::Readable,QDir::Name);
    for(const QFileInfo& fileInfo : fileInfoList)
    {
        QVariantMap result;
        QString fullpath = videoDir.filePath(fileInfo.fileName());
        result["mediaUrl"] = fullpath;
        result["mediaTitle"] = fileInfo.baseName();
        resultList.append(result);
    }
    return  resultList;
}

AppConfig::AppConfig(QObject *parent)
    : QObject(parent)
    ,videoDir(VIDEO_PATH)
{
    if(!videoDir.exists())
    {
        qDebug()<<"路径不存在"<<VIDEO_PATH;
    }
}
